package com.yw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yw.heroInfo.domain.Hero;
import com.yw.heroInfo.vo.HeroQueryVO;
import com.yw.mapper.HeroMapper;
import com.yw.service.HeroService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HeroServiceImpl extends ServiceImpl<HeroMapper, Hero>
                                implements HeroService {


    @Override
    public List<Hero> getAllHeroByCityId(Integer cityId) {
        LambdaQueryWrapper<Hero> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Hero::getCityId,cityId);
        List<Hero> list = this.list(wrapper);
        return list;
    }

    @Override
    public List<Hero> getAllHeroByWarId(Integer warId) {
        LambdaQueryWrapper<Hero> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Hero::getWarId,warId);
        List<Hero> list = this.list(wrapper);
        return list;
    }

    @Override
    public List<Hero> getAllHeroByColumnId(Integer columnId) {
        LambdaQueryWrapper<Hero> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Hero::getColumnId,columnId);
        List<Hero> list = this.list(wrapper);
        return list;
    }

    @Override
    public Hero getHeroByDeed(String deed) {
        LambdaQueryWrapper<Hero> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Hero::getDeed,deed);
        Hero hero = this.getOne(wrapper);
        return hero;
    }

    @Override
    public List<HeroQueryVO> listHeroNameAndCity() {
        List<Hero> list = this.list();
        ArrayList<HeroQueryVO> nameAndCityList = new ArrayList<>();
        for (Hero hero : list) {
            HeroQueryVO heroQueryVO = new HeroQueryVO();
            heroQueryVO.setHeroName(heroQueryVO.getHeroName());
            heroQueryVO.setHeroCity(heroQueryVO.getHeroCity());
            nameAndCityList.add(heroQueryVO);
        }
        return nameAndCityList;
    }
}
